<%@page import="models.Answer"%>
<%@page import="java.util.List"%>
<%@page import="service.ProgressTestDao"%>
<%@page import="org.hibernate.Session"%>
<%@page import="service.HibernateUtil"%>
<%@page import="models.Question"%>
<%@page import="java.util.Set"%>
<%@page import="models.Test"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <link href="style/general.css" type="text/css" rel="Stylesheet">
        <link rel="stylesheet" href="style/slideshow.css" />

        <!-- include jQuery Library From Google Code -->
        <script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js" type="text/javascript"></script>
        <link rel="Stylesheet" href="style/student.css" type="text/css" >

        <title>
            Three 2 Learn | Student
        </title>
        <!-- The main style sheet -->
        <link rel="stylesheet" href="style/login.css" type="text/css" media="screen" />

        <!-- START Fx.Slide -->
        <!-- The CSS -->
        <link rel="stylesheet" href="style/fx.slide.css" type="text/css" media="screen" />
        <!-- Mootools - the core -->
        <script type="text/javascript" src="js/mootools-1.2-core-yc.js"></script>
        <!--Toggle effect (show/hide login form) -->
        <script type="text/javascript" src="js/mootools-1.2-more.js"></script>
        <script type="text/javascript" src="js/fx.slide.js"></script>
        <!-- END Fx.Slide -->
    </head>
    <body>
        <jsp:useBean id="inhoud" scope="application" class="models.Bean" />   
        <jsp:setProperty name="inhoud" property="language" value="<%= models.Bean.getLanguage()%>" />
        <!-- Login -->
        <div id="login">
            <div class="loginContent">
                <form action="login" method="post">
                    <label for="log"><b>Username: </b></label>
                    <input class="field" type="text" name="userName" id="userName" value="" size="23" />
                    <label for="pwd"><b>Password:</b></label>
                    <input class="field" type="password" name="passWord" id="passWord" size="23" />
                    <input type="submit" name="submit" value="" class="button_login" />
                    <input type="hidden" name="redirect_to" value=""/>
                </form>
                <div class="left">
                    <label for="rememberme"><input name="rememberme" id="rememberme" class="rememberme" type="checkbox" checked="checked" value="forever" /> Remember me</label></div>
                <div class="right">Not a member? <a href="student/register">Register</a> | <a href="#">Lost your password?</a></div>
            </div>
            <div class="loginClose"><a href="#" id="closeLogin">Close Panel</a></div>
        </div> <!-- /login -->

        <div id="container">

            <div id="wrapper">
                <div id="header">
                    <div id="topmenu">
                        <ul class="login">
                            <li><img src="style/logo32L.png"/></li>
                            <li><a href="/language?lang=nl" title="Nederlands"><img src="images/flags/nl.png"></a></li>
                            <li><a href="/language?lang=en" title="English"><img src="images/flags/uk.png"></a></li>
                                    <c:choose>
                                        <c:when test="${loggedin eq 'true'}">
                                                        <li><a href="/logout" id="toggleLogout" >
                                                                <jsp:setProperty name="inhoud" property="key" value="LogOut" />
                                                                <jsp:getProperty name="inhoud" property="key" />
                                                            </a></li>
                                                        <li><a href="/${omgeving}" >
                                                                <jsp:setProperty name="inhoud" property="key" value="BackTo" />
                                                                <jsp:getProperty name="inhoud" property="key" /> ${omgeving}
                                                                <jsp:setProperty name="inhoud" property="key" value="TheEnvironment" />
                                                                <jsp:getProperty name="inhoud" property="key" />
                                                            </a></li>
                                                        <li><h2><jsp:setProperty name="inhoud" property="key" value="Welcome" />
                                                                <jsp:getProperty name="inhoud" property="key" />, ${user.firstName} ${user.lastName}</h2></li>
                                                            </c:when>
                                    <c:otherwise>
                                    <li><a href="#" id="toggleLogin" >
                                            <jsp:setProperty name="inhoud" property="key" value="Login" />
                                            <jsp:getProperty name="inhoud" property="key" />
                                        </a></li>
                                    </c:otherwise>
                                </c:choose>

                        </ul>
                    </div>
                    <div class="middle">
                        <div id="menu">
                            <ul>
                                <li><a href="/index">
                                        <jsp:setProperty name="inhoud" property="key" value="Homepage" />
                                        <jsp:getProperty name="inhoud" property="key" />
                                    </a></li>
                                <li><a href="/courses">
                                        <jsp:setProperty name="inhoud" property="key" value="Courses" />
                                        <jsp:getProperty name="inhoud" property="key" />
                                    </a></li>

                                <li><a href="three2Learn.jsp">Three2Learn</a></li>
                                <li><a href="information.jsp">

                                        <jsp:setProperty name="inhoud" property="key" value="Information" />

                                        <jsp:getProperty name="inhoud" property="key" />
                                    </a></li>
                                <li><a href="faq.jsp">

                                        <jsp:setProperty name="inhoud" property="key" value="FAQ" />
                                        <jsp:getProperty name="inhoud" property="key" />
                                    </a></li>

                                <li><a href="contact.jsp" class="lastItem">Contact</a></li>
                            </ul>
                        </div>
                    </div>
                </div>
                <div id="subcontainer">
                    <center>
                        <h1>Tests</h1>
                        <a href="/courseEnvironment.jsp"><img src="style/icons/return.png"/></a> 
                    </center>

                    <c:if test="${not empty courseTests}">
                        <table width="100%">
                            <th colspan="3"><jsp:setProperty name="inhoud" property="key" value="AllTests" />
                                <jsp:getProperty name="inhoud" property="key" /></th>
                            <tr>
                                <c:forEach var="tempTest" items="${courseTests}">
                                    <c:if test="${not loop.first and loop.index % 2 == 0}">
                                    </tr><tr>
                                    </c:if>
                                    <td class="darker"width="25%">
                                        ${tempTest.name}</td>
                                    <td>
                                        <a class="button" href="/progressStudent?type=participate&st=${tempTest.testID}">
                                            <jsp:setProperty name="inhoud" property="key" value="EnrollForTest" />
                                            <jsp:getProperty name="inhoud" property="key" /></a>

                                        <a class="button" href="/progressStudent?type=overzicht&st=${tempTest.testID}">
                                            <jsp:setProperty name="inhoud" property="key" value="SeeGrades" />
                                            <jsp:getProperty name="inhoud" property="key" /> </a>
                                    </td>
                                </c:forEach>
                            </tr>
                        </table>
                    </c:if>
                    <c:if test="${empty courseTests}">
                        <center>
                            <jsp:setProperty name="inhoud" property="key" value="NoTests" />
                            <jsp:getProperty name="inhoud" property="key" />
                        </center>
                    </c:if>

                    <c:if test="${not empty grade}">
                        <h2><jsp:setProperty name="inhoud" property="key" value="YourGrade" />
                            <jsp:getProperty name="inhoud" property="key" />: ${grade} of the 100%</h2>
                        </c:if>

                    <c:if test="${not empty selectedTest and not empty testQuestions}">

                        <table width="100%">
                            <form method="post" action="progressStudent?type=grade">
                                <th colspan="2">Test: ${selectedTest.name}</th>
                                <tr class="darker">
                                    <td>
                                        <b>
                                            <jsp:setProperty name="inhoud" property="key" value="Questions" />
                                            <jsp:getProperty name="inhoud" property="key" />
                                        </b>
                                    </td>
                                    <td>
                                        <b>
                                            <jsp:setProperty name="inhoud" property="key" value="Answers" />
                                            <jsp:getProperty name="inhoud" property="key" />
                                        </b>
                                    </td>
                                </tr>                
                                <c:forEach var="tempQuestion" items="${testQuestions}">
                                    <tr>
                                        <td width="40%">${tempQuestion.question}</td>
                                        <%
                                            HibernateUtil HU = new HibernateUtil();
                                            Session s = HU.openSession();
                                            ProgressTestDao pdao = new ProgressTestDao(s);
                                            Question q = (Question) pageContext.getAttribute("tempQuestion");
                                            try {
                                                List<Answer> answers = pdao.getAnswers(q.getQuestionID());
                                                pageContext.setAttribute("answers", answers);
                                            } catch (Exception e) {
                                                System.out.println(e);
                                            }

                                        %>
                                        <td>
                                            <c:forEach var="tempAnswer" items="${answers}">
                                                <input type="radio" value="${tempAnswer.answerID}" name="${tempQuestion.questionID}"/>${tempAnswer.answer} </br>
                                            </c:forEach>
                                        </td>
                                    </tr>                        
                                </c:forEach>
                                <tr class="darker">
                                    <td colspan="2">
                                        <input type="submit" value="Grade Test"/>
                                    </td>
                                </tr>
                            </form>
                        </table>
                    </c:if>
                    
                    <c:if test="${not empty results}">
                        <table width="100%">
                            <th colspan="2">
                                <jsp:setProperty name="inhoud" property="key" value="Results" />
                            <jsp:getProperty name="inhoud" property="key" />
                                ${selectedTest.name}</th>
                            <tr class="darker"><td><jsp:setProperty name="inhoud" property="key" value="Date" />
                            <jsp:getProperty name="inhoud" property="key" /></td>
                                <td><jsp:setProperty name="inhoud" property="key" value="YourGrade" />
                            <jsp:getProperty name="inhoud" property="key" /></td></tr>
                            <c:forEach var="grade" items="${results}">
                                <tr><td>${grade.date}</td><td>${grade.grade}%</td></tr>
                            </c:forEach>
                        </table>
                    </c:if>
                </div>
            </div>
        </div>
    </body>
</html>
